package com.gis.entity;

import java.util.List;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;


@Data
public class SLDStyle {
    @TableField(exist = false)
    List<ColorMapEntry> colorMapEntries;

    String name;

    @TableField(exist = false)
    String filename;
    // 这里为了适应 Geoserver 中 api的要求，需要有个style的名字

    @TableField(exist = false)
    String fixedContent = 
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
                "<sld:StyledLayerDescriptor xmlns:sld=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:gml=\"http://www.opengis.net/gml\" version=\"1.0.0\">\r\n" + //
                "  <sld:NamedLayer>\r\n" + //
                "    <sld:Name>NoramlizationStyle</sld:Name>\r\n" + //
                "    <sld:UserStyle>\r\n" + //
                "      <sld:Title>Noramlization Style</sld:Title>\r\n" + //
                "      <sld:FeatureTypeStyle>\r\n" + //
                "        <sld:Rule>\r\n" + //
                "          <sld:RasterSymbolizer>\r\n" + //
                "            <sld:ColorMap>" + //
                "替换标识符号\r\n" + //
                "            </sld:ColorMap>\r\n" + //
                "          </sld:RasterSymbolizer>\r\n" + //
                "        </sld:Rule>\r\n" + //
                "      </sld:FeatureTypeStyle>\r\n" + //
                "    </sld:UserStyle>\r\n" + //
                "  </sld:NamedLayer>\r\n" + //
                "</sld:StyledLayerDescriptor>";
    public String getSLDStyle() {
        if (this.colorMapEntries == null || this.colorMapEntries.isEmpty()) {
            throw new IllegalArgumentException("colorMapEntries属性不能为空");
        }
        StringBuilder sb = new StringBuilder();
        for (ColorMapEntry entry : this.colorMapEntries) {
            sb.append(entry.toString());
        }
        return fixedContent.replace("替换标识符号", sb.toString());
    }
    
}
